package com.xwj.validation.group.controller;

import com.alibaba.fastjson.JSON;
import com.xwj.common.util.R;
import com.xwj.validation.group.dto.StudentDTO;
import com.xwj.validation.group.groups.AddGroup;
import com.xwj.validation.group.groups.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: xiaowajiang
 * @Date: 2022-03-13 20:41
 * @Description: 分组场景参数校验
 **/
@Slf4j
@RestController
@Api(value = "GroupValidController", tags = "分组校验")
public class GroupValidController {

    @ApiOperation(value = "新增操作", notes = "通过 AddGroup 来指定分组场景，校验失败后，抛出 MethodArgumentNotValidException 异常")
    @PostMapping("group/valid/student/save")
    public R save(@Validated(value = AddGroup.class) @RequestBody StudentDTO stu) {
        log.info("保存学员信息，入参：{}", JSON.toJSONString(stu));
        // 业务逻辑
        return R.ok();
    }

    @ApiOperation(value = "修改操作", notes = "通过 UpdateGroup 来指定分组场景，校验失败后，抛出 MethodArgumentNotValidException 异常")
    @PostMapping("group/valid/student/update")
    public R update(@Validated(value = UpdateGroup.class) @RequestBody StudentDTO stu) {
        log.info("修改学员信息，入参：{}", JSON.toJSONString(stu));
        // 业务逻辑
        return R.ok();
    }
}
